package net.zoneland.zrdp.common.config;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * 读取项目相关配置
 *
 * @author zonevue
 */
@Component
@ConfigurationProperties(prefix = "zonevue")
@Getter
@Setter
@ToString
public class ZonevueConfig
{
    /** 项目名称 */
    private String name;

    /** 版本 */
    private String version;

    /** 版权年份 */
    private String copyrightYear;

    /** 实例演示开关 */
    private boolean demoEnabled;

    /** 上传路径 */
    private String profile;

    /** 获取地址开关 */
    private boolean addressEnabled;

    /** 验证码类型 */
    private String captchaType;

    private String tablePrefix;

    /** 登陆解密用 secretKey */
    private String secretKey;

    /** 登陆解密用 iv */
    private String iv;

    /** redis key 前缀  */
    private String redisPrefix;

    /** 是否开启浙江移动sso认证 */
    private boolean ssoEnabled;

    /** 浙江移动sso认证的访问地址 */
    private String ssoUrl;

    /** 浙江移动获取用户信息的接口地址 */
    private String ssoWebLoginedUserUrl;


    @Value("${zrdpAppTablePrefix}")
    public void setTablePrefix(String tablePrefix) {
        this.tablePrefix = tablePrefix;
    }

    @Value("${zonevue.sso.ssoWebLoginedUserUrl}")
    public void setSsoWebLoginedUserUrl(String ssoWebLoginedUserUrl) {
        this.ssoWebLoginedUserUrl = ssoWebLoginedUserUrl;
    }

    @Value("${zonevue.sso.enabled:false}")
    public void setSsoEnabled(boolean ssoEnabled) {
        this.ssoEnabled = ssoEnabled;
    }

    @Value("${zonevue.sso.ssoUrl}")
    public void setSsoUrl(String ssoUrl) {
        this.ssoUrl = ssoUrl;
    }



    /**
     * 获取导入上传路径
     */
    public String getImportPath()
    {
        return this.profile + "/import/";
    }

    /**
     * 获取头像上传路径
     */
    public String getAvatarPath()
    {
        return this.profile + "/avatar/";
    }

    /**
     * 获取下载路径
     */
    public String getDownloadPath()
    {
        return this.profile + "/download/";
    }

    /**
     * 获取上传路径
     */
    public String getUploadPath()
    {
        return this.profile + "/upload/";
    }

    /**
     * 代码文件生成路径
     */
    public String getGenPath() {
        return this.profile + "/gen/";
    }

    public String toRedisKey(final String key) {
        if (key.startsWith(redisPrefix)) {
            return key;
        }
        return redisPrefix + key;
    }
}
